<script setup>
import { ref, reactive } from 'vue'
import {basic,updbasic} from  '@/api/basi.js'
import addressbook from './addressBook.vue'
import customerContact from './customerContact.vue';
import selfBuiltApp from './selfBuiltApp.vue';
import bottomCopyringht from '../../../components/bottom-copyright.vue'
const form = reactive({
  corp_name: '',
  corp_id: ''
})
const ruleFormRef = ref()
const submitForm1 = async (formEl) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      console.log('submit!')
      updbasic(form).then(res=>{
        ElMessage({
          message: '修改成功',
          type: 'success',
        })
      })
    } else {
      console.log('error submit!', fields)
    }
  })
}
const basicapi = ()=>{
  basic().then(res=>{
    form.corp_name=res.data.corp_name
    form.corp_id=res.data.corp_id
  })
}
basicapi()
const resetForm1 = (formEl) => {
  if (!formEl) return
  formEl.resetFields()
  console.log('77')
}



const list = reactive(
  ['基础设置',  '客户联系', '自建应用']
)
const currentIndex = ref(0)
const module = ref('基础设置')
const change = (index, item) => {
  module.value = item
  console.log(module.value)
  currentIndex.value = index
}
const communications = ref(null)
const customer = ref(null)
const app = ref(null)
const communication=()=>{
  communications.value.preservation(true)
}
const customers =()=>{
  customer.value.preservation()
}
const apps=()=>{
  app.value.updselfappapi()
}
</script>
<template>
  <div>
    <div class="topTabStyle">
      <div class="tabStyleChild">
        <div :class='{ tabSelect: index === currentIndex }' v-for="(item, index) in list" @click="change(index, item)">
          {{ item }}
        </div>
      </div>
      <div v-if="module == '基础设置'" class="cardContent">
        <div class="cardTabTop">
          <div class="cardTabTop1"></div>
          <div class="cardTabTop2">基础设置</div>
        </div>
        <div class="cardFormStyle">
          <el-form :model="form" label-width="120px" ref="ruleFormRef" style="margin-top:-5px">
            <el-form-item label="企业名称">
              <el-input v-model="form.corp_name" />
            </el-form-item>
            <el-form-item label="CorpID">
              <el-input v-model="form.corp_id" />
            </el-form-item>
          </el-form>
        </div>
      </div>
      <div v-else-if="module === '通讯录'">
     <addressbook ref="communications"></addressbook>
      </div>
      <div v-else-if="module === '客户联系'">

        <customerContact ref="customer"></customerContact>
      </div>
      <div v-else-if="module === '自建应用'">
        <selfBuiltApp ref="app"></selfBuiltApp>
      </div>
      <!-- 按钮 -->
      
      <div>
      </div>
    </div>
   
    <div class="bottomButton" v-if="module === '基础设置'">
      <!-- <el-button @click="resetForm1(ruleFormRef)">取消</el-button> -->
      <el-button type="primary" @click="submitForm1(ruleFormRef)">保存</el-button>
    </div>
     <div class="bottomButton" v-else-if="module === '通讯录'">
      <!-- <el-button>取消</el-button> -->
      <el-button type="primary" @click="communication">保存</el-button>
    </div>
     <div class="bottomButton" v-else-if="module === '客户联系'">
      <!-- <el-button>取消</el-button> -->
      <el-button type="primary" @click="customers">保存</el-button>
    </div>
     <div class="bottomButton" v-else-if="module === '自建应用'">
      <!-- <el-button>取消</el-button> -->
      <el-button type="primary" @click="apps()">保存</el-button>
    </div>
    <bottomCopyringht style="position: fixed;
      bottom: 80px;
      width: 100%;
      
      text-align: center;
      padding-right: 100px;
      
      "></bottomCopyringht>



  </div>
</template>
<style scoped >
.topTabStyle {
  position: relative;
  height: 65px;
  margin: 20px;
  background: #FFFFFF;
  box-shadow: 0px 2px 8px 0px rgba(0, 0, 0, 0.0400);
  border-radius: 15px;
}

.tabStyleChild {
  width: 280px;
  height: 65px;
  line-height: 65px;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #8c8c8c;
  margin-left: 40px;
  display: flex;
  justify-content: space-between;
}

.tabSelect {
  text-align: center;
  border-bottom: 3px solid #208EFF;
  color: #208EFF;
}

.cardContent {
  background: #FFFFFF;
  margin-top: 20px;
  box-shadow: 0px 2px 8px 0px rgba(0, 0, 0, 0.0400);
  border-radius: 8px;
}

.el-form-item {
  margin-bottom: 24px;
}

.cardTabTop {
  height: 66px;
  display: flex;
  margin-left: 25px;
  margin-top: 24px;
  padding-top: 23px;
  justify-content: flex-start;
}

.cardTabTop1 {
  width: 4px;
  height: 14px;
  background: #208EFF;
}

.cardTabTop2 {
  width: 56px;
  height: 14px;
  margin-left: 5px;
  font-size: 14px;
  font-family: PingFang-SC-Medium, PingFang-SC;
  font-weight: 500;
  color: #333333;
  line-height: 14px;
}

.cardFormStyle {
  width: 440px;
  padding-bottom: 24px;
  margin-left: 115px;
}

.bottomButton {
  position: fixed;
  bottom: 0;
  width: 100%;
  line-height: 60px;
  text-align: center;
  padding-right: 100px;
  height: 60px;
  background-color: #FFFFFF;
}
</style>